<?php

declare(strict_types=1);

namespace Core\Package\ElementPlus\FormCreate\FormItem;

/**
 * element-plus input
 */
class Input extends FormItemAbstract
{
    protected string $_type = 'input';

    /**
     * 获取值类型
     * @return string
     */
    public function valueType(): string
    {
        return self::VALUE_TYPE_STRING;
    }

    protected function defaultProps(): array
    {
        return [
            'show-word-limit' => true,//是否显示字数信息
            'autofocus' => false,//是否自动获取焦点

        ];
    }


    public function __construct(string $field, string $title, string $value = '')
    {
        $this->_title = $title;
        $this->_field = $field;
        $this->_value = $value;
    }


    /**
     * 设置是否自动获取焦点
     * @param bool $autofocus
     * @return Input
     */
    public function autofocus(bool $autofocus): Input
    {
        return $this->props('autofocus', $autofocus);
    }


    /**
     * 最少输入字符
     * @param int $minlength
     * @return Input
     */
    public function minlength(int $minlength): Input
    {
        return $this->props('minlength', $minlength);
    }


    /**
     * 最多输入字符
     * @param int $maxlength
     * @return Input
     */
    public function maxlength(int $maxlength): Input
    {
        return $this->props('maxlength', $maxlength);
    }


    /**
     * 表单提示
     * @param string $placeholder
     * @return Input
     */
    public function placeholder(string $placeholder): Input
    {
        return $this->props('placeholder', $placeholder);
    }


    /**
     * 表单是否只读
     * @param bool $readonly
     * @return Input
     */
    public function readonly(bool $readonly): Input
    {
        return $this->props('readonly', $readonly);
    }


    /**
     * 是否显示字数
     * @param bool $showWordLimit
     * @return Input
     */
    public function showWordLimit(bool $showWordLimit): Input
    {
        return $this->props('show-word-limit', $showWordLimit);
    }
}